define(['app'], function(app) {
	'use strict';

	var controller = function controller($scope, Newpro_ads,GoPage,$timeout) {
		//广告编辑页面
		$scope.onshow_ads = function(act_id){
			GoPage.go_states("ads",{"act_id":act_id});
		}

		  $scope.init_data = function() {
			  Newpro_ads.get_list(1,function(data) {
			        // console.log(data);
					$scope.data = data;
				});
			}
		  $scope.init_data(); //必须在定义之后

		  //下拉刷新
        $scope.input = new Object();
        $scope.input.nPage = 1;
        $scope.isLoad = false; //可以加载
        //下拉刷新 判断哪个模块进行刷新
        $scope.doRefresh = function() {
            //防止重复加载
            $scope.isLoad = true;
            Newpro_ads.get_list(1,function(data) {
                    console.log(data);
                    if(data != null) {
                        $scope.data = data;

                    } else
                        $scope.data = new Object();
                    $scope.input.nPage = 1;
                },
                function() {
                    $scope.$broadcast('scroll.refreshComplete');
                    $timeout(function() {
                        $scope.isLoad = false;
                    }, 1500);
                });
        };
        //加载更多
        $scope.doRefreshMore = function() {
            //防止重复加载
            $scope.isLoad = true;
            Newpro_ads.get_list($scope.input.nPage +1,function(data){
                    console.log(data);
                    if(data != null) {
                        if($scope.data.act != undefined) {
                            $scope.data.act = $scope.data.act.concat(data.act);
                            $scope.input.nPage += 1;
                        } else {
                            $scope.data = data;
                        }

                    }
                },
                function() {
                    $scope.$broadcast('scroll.infiniteScrollComplete');
                    $timeout(function() {
                        $scope.isLoad = false;
                    }, 1500);

                });

        };


	}

	controller.$inject = ['$scope', 'Newpro_ads','GoPage','$timeout'];

	return app.registerController("newpro_adsctrl",controller);
});